<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        body {
            background-image: url("./image/cspy1.jpg");
            background-repeat: no-repeat;
            background-size: cover;
            display: flex;
            justify-content: center;
            align-items: center;
        }

        .container {
            background-color: rgba(255, 255, 255, 0.8);
            border: 2px solid orange;
            margin: 0 auto;
            width: 350px;
            height: 300px;
            display: flex;
        }

        .button input {
            width: 350px;
            border: none;
            background-color: orange;
            border-radius: 10px;
            margin-top: 10px;
        }

        .container span {
            display: block;
            justify-content: center;
            align-items: center;
        }

        .select {
            margin-left: 130px;
        }
    </style>
</head>

<body>
    <div class="container">
        <form action="http://47.115.227.93:8080/upload" method="post" enctype="multipart/form-data">
            <span class="select"><input type="file" name="file"></span><br>
            <span class="button"><input type="submit" value="上传"></span>
        </form>
    </div>
</body>
<script>
    //检测cookie
    checkCookie();

    //获取cookie
    function getCookie(cname) {
        var name = cname + "=";
        var ca = document.cookie.split(';');
        for (var i = 0; i < ca.length; i++) {
            var c = ca[i].trim();
            if (c.indexOf(name) == 0) return c.substring(name.length, c.length);
        }
        return "";
    }

    //检测cookie
    function checkCookie() {
        var username = getCookie("username");
        if (username != "") 
        {
            //已经登录的,不需要跳转
        }
        else {
            //重定向,防止持续输出
            window.location.href = "http://47.115.227.93:8080/LogIn.html";
            //输出
            alert("你还未登录");

            // username = prompt("Please enter your name:","");
            // if (username!="" && username!=null)
            // {
            // setCookie("username",username,365);
            // }
        }
    }

    //获取url
    let url = window.location.href;
    if (url.lastIndexOf("?") != -1) {
        url = decodeURI(url);//解码
        //找到问号
        let pos = url.lastIndexOf("?");
        //切割后面的内容
        let message = url.slice(pos + 1);
        //&分隔符会被识别为%26
        if (message.lastIndexOf('%26') == -1)//提交成功
        {
            //重定向,防止持续输出
            window.location.href = "http://47.115.227.93:8080/Upload.html";
            //输出
            alert(message);
        }
        else {
            //TODO
        }
    }
</script>

</html>